﻿@model SIFIET.Models.Vacancy

@{
    ViewBag.Title = "Publicar Vacante";
}

@if(null != TempData["alertMessage"])
{
    <script type="text/javascript">
        alert("Error: Compañia inexistente, si es necesario cree una nueva.");
    </script>
}


<h1>Publicar nueva vacante laboral</h1>

<script type="text/javascript" language="javascript">
    function __doPostBack(eventTarget, eventArgument) {
        if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
            theForm.__EVENTTARGET.value = eventTarget;
            theForm.__EVENTARGUMENT.value = eventArgument;
            theForm.submit();
        }
    }         
</script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

@using (Html.BeginForm()) {
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>Por favor, ingrese la siguiente información</legend>
        <p>Todos los campos son obligatorios</p>
        <div class="editor-label">
            Compañía que ofrece el cargo (seleccione una de la lista)
        </div>

        <div class="editor-field">
            <input type="text" name="txtCompanie" id="txtCompanie" style = "width:150px" />            
            ¿No aparece en la lista? &nbsp<a class="ebutton blue" href="../Companies/Create">Crear Nueva</a>
        </div>         

        <script type="text/javascript" language="javascript">
            $(document).ready(function () {
                $('#txtCompanie').autocomplete({
                    source: '@Url.Action("AutocompleteCompanies")'
                });
            }) 
        </script>      

       <script type="text/javascript" language="javascript">
           function setNombreCompania() {
               var nombreCom = document.getElementById('txtCompanie');
               __doPostBack("getNombreCompania", nombreCom.value);
           }
        </script>

        @*<div class="editor-field">
            @Html.DropDownList("IdCompanie", "")
            @Html.ValidationMessageFor(model => model.IdCompanie)

            ¿No aparece en la lista? &nbsp<a class="ebutton blue" href="../Companies/Create">Crear Nueva</a>
        </div>*@

       @* <div class="editor-field">
            <input type="text" name="txtCompanie" id="txtCompanie" style = "width:150px" />
            ¿No aparece en la lista? &nbsp<a class="ebutton blue" href="../Companies/Create">Crear Nueva</a>
        </div>*@
        
      

        <div class="editor-label">
            Cargo ofrecido
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Charge)
            @Html.ValidationMessageFor(model => model.Charge)
        </div>

        <div class="editor-label">
            Jornada de trabajo
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.DayTrip)
            @Html.ValidationMessageFor(model => model.DayTrip)
        </div>

        <div class="editor-label">
            Número de horas de la jornada de trabajo
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.HoursNumber)
            @Html.ValidationMessageFor(model => model.HoursNumber)
        </div>

        <div class="editor-label">
            Perfil Profesional requerido
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.ProfessionalProfile)
            @Html.ValidationMessageFor(model => model.ProfessionalProfile)
        </div>

   
        <div class="editor-label">
            Fecha de Cierre (dd/mm/yyyy)
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(model => model.ClosingDate, new { id = "closingdate" })
            @Html.ValidationMessageFor(model => model.ClosingDate)
        </div>

        <script type="text/javascript">
            $(document).ready(function () {
                $("#closingdate").datepicker({ dateFormat: 'dd/mm/yy' });
            });
        </script>

        <div class="editor-label">
            Número de Vacantes ofrecidas
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.VacanciesNumber)
            @Html.ValidationMessageFor(model => model.VacanciesNumber)
        </div>

        <div class="editor-label">
           Salario ofrecido (sin comas o puntos)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Salary)
            @Html.ValidationMessageFor(model => model.Salary)
        </div>

        <script type="text/javascript">
            $.validator.methods.number = function (value, element) {
                value = floatValue(value);
                return this.optional(element) || !isNaN(value);
            }
            $.validator.methods.range = function (value, element, param) {
                value = floatValue(value);
                return this.optional(element) || (value >= param[0] && value <= param[1]);
            }

            function floatValue(value) {
                return parseFloat(value.replace(",", "."));
            }  
        </script>
        <div class="editor-label">
            Descripción
        </div>
        <div class="editor-field">
            @Html.TextAreaFor(model => model.Description, htmlAttributes: new { rows="5%", cols="45%", placeholder="Escriba una descripción informativa acerca esta vacante"})
            @Html.ValidationMessageFor(model => model.Description)
        </div>
        <br/>
        <p>
             <input type="submit" value="Crear" class="ebutton blue" /> &nbsp;
             @Html.ActionLink("Volver a la lista", "Index", null, htmlAttributes: new { @class = "ebutton blue" })
        </p>
    </fieldset>
}

